<template>
  <div>
    <template>
      <el-table :data="tableData" height="250" border style="width: 100%">
        <el-table-column label="姓名" width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.student_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="日期" width="180">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{
              scope.row.message_date | formatData
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="留言" width="850">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{
              scope.row.message_content
            }}</span>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>
<script>
export default {
  created () {
    this.studentmessage();
  },
  data () {
    return {
      tableData: [],
    };
  },
  filters: {
    formatData (time) {
      return new Date(time).toLocaleString();
    },
  },
  methods: {
    studentmessage () {
      const n = window.location.hash.substring(26);
      // console.log(n);
      this.$http
        .post("http://127.0.0.1:8080/teacher/studentmessage?student_num=" + n)
        .then((res) => {
          if (res.data.status == 0) {
            res.data.data[0].forEach((val) => {
              res.data.data[1].forEach((value) => {
                if (val.student_num == value.student_num) { Object.assign(val, { student_name: value.student_name }); }
              });
            });
            this.tableData = res.data.data[0];
          } else {
            this.$message.error(res.data.message);
          }
        });
    },
  },
};
</script>
<style lang="less" scoped>
</style>
